#include<iostream>
#include<cmath>
using namespace std;

struct student {
    int chinese;
    int math;
    int english;
    int sum;
};

int main() {
    int n, i, j, count = 0;
    cin >> n;
    student s[1000];
    for (i = 0; i < n; i++) {
        cin >> s[i].chinese >> s[i].math >> s[i].english;
        s[i].sum = s[i].chinese + s[i].math + s[i].english;
    }
    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            if (abs(s[i].chinese - s[j].chinese) <= 5 &&
                abs(s[i].math - s[j].math) <= 5 &&
                abs(s[i].english - s[j].english) <= 5 &&
                abs(s[i].sum - s[j].sum) <= 10) {
                count++;
            }
        }
    }
    cout << count;
    return 0;
}